<!--  设置招生专业  -->
<template>
  <div class="assessment-container" style="width:100%">
    <div class="search-container" style="margin:0;padding-left:0">
      <div class="search-container-left">
        <div class="search-container-item">
          <span>课程负责单位：</span>
          <el-select
            v-model="searchParams.department"
            style="width: 140px;margin-right:5px"
            size="mini"
            placeholder="请选择"
            @change="handleXb"
            clearable
          >
            <el-option
             style="margin-right:5px"
              v-for="(item,index) in xbList"
              :key="index"
              :label="item.deptName"
              :value="item.deptName"
            >
            </el-option>
          </el-select>
          <el-select
            v-model="searchParams.teachingandresearchsection"
            style="width: 140px"
            size="mini"
            placeholder="请选择"
            @change="handleClass"
            clearable
          >
            <el-option
              v-for="(item,index) in gClassList"
              :key="index"
              :label="item.deptName ? item.deptName : item.value"
              :value="item.deptName ? item.deptName : item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="search-container-item" style="margin-left:15px">
          <span style="color:#004ca7">培养层次：</span>
          <el-select
            v-model="searchParams.traininglevel"
            style="width: 140px"
            size="mini"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="(item,index) in pyccList"
              :key="index"
              :label="item.dictValue"
              :value="item.dictKey"
            >
            </el-option>
          </el-select>
        </div>
        <div class="search-container-item" style="margin-left:15px">
          <span style="color:#004ca7">修习类型：</span>
          <el-select v-model="searchParams.studytype" size="mini" placeholder="请选择" clearable style="width: 140px">
            <el-option
            v-for="(item,index) in xxlxList"
            :key="index"
            :label="item"
            :value="item"
            >
            </el-option>
        </el-select>
        </div>
        <div class="search-container-item">
          <span>课程编号：</span>
          <el-input
            style="width: 140px"
            size="mini"
            placeholder="请输入内容"
            v-model="searchParams.coursenumber"
            clearable
          ></el-input>
        </div>
        <div class="search-container-item">
          <span>课程名称：</span>
          <el-input
            style="width: 140px"
            size="mini"
            placeholder="请输入内容"
            v-model="searchParams.coursename"
            clearable
          ></el-input>
        </div>
        <!-- <el-button type="primary" size="mini" icon="el-icon-search" @click="clickSearch">查 询</el-button> -->
        <div class="search-button" style="margin:2px 0 0 0" @click="clickSearch">
          <img src="../../../assets/assessment/icon-search.png" alt="" />
          <span>查询</span>
        </div>
      </div>
    </div>
    <div style="display: flex; width: 100% !important;margin-top:15px">
      <table style="width:100%">
        <tr>
          <td style="width:50%" valign="top">
            <div class="title1"><span class="span1">选择课程（{{ tableData1.length }}个）</span></div>
              <el-table
                :data="tableData1"
                ref="ass"
                class="xpaas-table-class"
                row-class-name="xpaas-row-class"
                cell-class-name="xpaas-cell-class"
                header-row-class-name="xpaas-header-row-class"
                header-cell-class-name="xpaas-header-cell-class"
                @selection-change="handleSelectionChange"
              >
                <el-table-column type="selection" width="60" align="center"></el-table-column>
                <el-table-column prop="department" label="系" align="center"></el-table-column>
                <el-table-column prop="teachingandresearchsection" label="教研室" align="center"></el-table-column>
                <el-table-column prop="traininglevel" label="培养层次" align="center"></el-table-column>
                <el-table-column prop="coursetype" label="修习类型" align="center"></el-table-column>
                <el-table-column prop="coursenumber" label="课程编号" align="center"></el-table-column>
                <el-table-column prop="coursename" label="课程名称" align="center"></el-table-column>
              </el-table>
          </td>
          <td>
            <img src="@/assets/assessment/enjiantou.png" @click="tj" />
          </td>
          <td valign="top" style="width:50%">
          <div class="title2"><span class="span2">已选课程（{{ tableData2.length }}个）</span></div>
          <el-table
            :data="tableData2"
            class="xpaas-table-class"
            row-class-name="xpaas-row-class"
            cell-class-name="xpaas-cell-class"
            header-row-class-name="xpaas-header-row-class"
            header-cell-class-name="xpaas-header-cell-class"
          >
            <el-table-column prop="department" label="系" align="center"></el-table-column>
            <el-table-column prop="teachingandresearchsection" label="教研室" align="center"></el-table-column>
            <el-table-column prop="traininglevel" label="培养层次" align="center"></el-table-column>
            <el-table-column prop="coursetype" label="修习类型" align="center"></el-table-column>
            <el-table-column prop="coursenumber" label="课程编号" align="center"></el-table-column>
            <el-table-column prop="coursename" label="课程名称" align="center"></el-table-column>
            <el-table-column prop="delete" label="删除" align="center">
              <template slot-scope="scope">
                <div
                  class="plsc-button"
                  @click="delOne(scope.row)"
                  style="width: 70px;margin:0 auto"
                >
                  <span>删 除</span>
                </div>
                <!-- <el-button type="danger" size="small" @click="pjByIdGuide(scope.$index)">删除</el-button> -->
              </template>
            </el-table-column>
          </el-table>
          </td>
        </tr>
      </table>
    </div>
    <div
      slot="footer" style="text-align:center;margin-top:50px"
    >
      <div class="button-group">
        <div @click="submitExam">返 回</div>
      </div>
    </div>
  </div>
</template>
<script>
import { getxb,getClass,queryXBclassroom } from "@/api/course/courses";
import { reqCheckLevelList } from "@/api/admin1/check";
import { selectAllCourse,addExaCourses,removePlanId } from "../../../api/courseAchievement/entryResults";
export default {
  data() {
    return {
        searchParams:{
            department:'',
            teachingandresearchsection:'',
            studytype:"",
            traininglevel:'',
            coursename: "",
            coursenumber:""
        },
        xbList:[],
        gClassList:[],
        pyccList: [],
        xxlxList:['必修', '选修'],
        tableData1: [],
        tableData2: [],
    };
  },
  mounted() {
    this.xbAll();
    this.classAll();
    this.reqCheckLevelList();
    this.clickSearch();
  },
  methods: {
        async xbAll(){
            const xb = await getxb();
            xb.data.code == 200 ? this.xbList = xb.data.data : [];
        },
        async classAll(){
            const gClass = await getClass();
            gClass.data.code == 200 ? this.gClassList = gClass.data.data : [];
        },
        // 教研室下拉框的改变
        handleClass(val){
            if(!val){
                this.xb ? this.handleXb(this.xb)  : this.classAll();
            }
        },
        // 根据系部选中获取教研室
        async handleXb(val){
            if(val){
                const xbClass = await queryXBclassroom(val);
                xbClass.data.code == 200 ? this.gClassList = xbClass.data.data : [];
                this.searchParams.teachingandresearchsection = ''
            } else {
                this.xbAll();
                this.classAll();
            }
        },
        //获取培养层次下拉框
        reqCheckLevelList(){
            let that = this;
            reqCheckLevelList().then(res => {
                if(res.data.code == 200 && res.data.data){
                that.pyccList = res.data.data[0].children;
                // that.traininglevel = res.data.data[0].children[0].dictValue;
                }
            });
        },
        //查询
        clickSearch(){
            return new Promise(() => {
                selectAllCourse(this.searchParams).then((res) => {
                    let arrNew = [];
                    res.data.data.forEach(element => {
                        element.courseimplementplan.id = element.id;
                        arrNew.push(element.courseimplementplan)
                    });
                    this.tableData1 = arrNew;
                });
                let searchRparams = {
                  department: this.searchParams.department,
                  teachingandresearchsection: this.searchParams.teachingandresearchsection,
                  studytype: this.searchParams.studytype,
                  traininglevel: this.searchParams.traininglevel,
                  coursename: this.searchParams.coursename,
                  coursenumber: this.searchParams.coursenumber,
                  planid: this.$route.query.id
                };
                selectAllCourse(searchRparams).then((res) => {
                    let arrNewR = [];
                    res.data.data.forEach(element => {
                      element.courseimplementplan.id = element.id;
                      arrNewR.push(element.courseimplementplan)
                    });
                    this.tableData2 = arrNewR;
                });
            });
        },
        handleSelectionChange(val) {
            this.tablelist = val;
        },
        //点击箭头向右侧添加数据
        tj() {
            var temp = this.tablelist.map((item, index) => {
                return item.id
            });
            this.tableData1 = this.tableData1.filter((e) => !temp.includes(e.id));
            this.tableData2 = [...this.tableData2, ...this.tablelist];
            addExaCourses(this.$route.query.id,temp.join(',')).then(res=>{
                if(res.data.code == 200){
                    this.clickSearch();
                }
            })
        },
        //返回
        submitExam(){
          this.$router.push({
              path: "/admin/planManagement/entryResultsage"
          });
        },
        //右侧单个删除
        delOne(row) {
          this.$confirm('确认要删除吗？')
            .then(_ => {
              removePlanId(row.id).then((res) => {
                if(res.data.code == 200 && JSON.stringify(res.data.data) === '{}'){
                  this.$message({
                    showClose: true,
                    message: '删除成功！',
                    type: "success",
                  });
                  this.clickSearch();
                } else {
                  this.$message({ type: "error", message: res.data.data, duration:5000 });
                  this.clickSearch();
                }
              })
            })
        },
        xyb(){
            let nd = this.$route.query.nd
            this.$router.push({ path: "/admin/professional/information",query: {tablelist:this.tableData2,nd:nd} });
        },
    },
};
</script>
<style scoped lang="less">
@import "../../../styles/print-entry.less";
.assessment-container {
  .export-report-container {
    .el-dialog__body {
      padding: 64px 0 64px 50px;
      .el-radio {
        margin-right: 79px;
      }
    }
    .el-dialog__footer {
      padding-bottom: 103px;
    }
  }
  .import-report-container {
    .el-dialog__body {
      padding-left: 165px;
      padding-top: 71px;
      padding-bottom: 60px;
      > div {
        > span {
          font-size: 18px;
          font-weight: bold;
          line-height: 20px;
          color: #004ca7;
          vertical-align: middle;
        }
        > input {
          width: 254px;
          height: 25px;
          border: 1px solid #004ca7;
          opacity: 1;
          border-radius: 4px;
          padding-left: 5px;
          margin-right: 8px;
          color: #004ca7;
          vertical-align: middle;
        }
        > div {
          display: inline-block;
          font-size: 18px;
          padding: 1px 10px;
          border-radius: 4px;
          vertical-align: middle;
          cursor: pointer;
          &:nth-child(3) {
            color: rgba(2, 200, 108, 1);
            background: #f1fff8;
            border: 1px solid #02c86c;
            position: relative;
            margin-right: 20px;
            > input {
              width: 0px;
              position: absolute;
              left: 0;
              opacity: 1;
              cursor: pointer;
            }
          }
          &:nth-child(4) {
            color: rgba(82, 48, 233, 1);
            background: rgba(235, 230, 255, 1);
            border: 1px solid rgba(82, 48, 233, 1);
          }
        }
      }
    }
    .el-dialog__footer {
      padding-bottom: 76px;
      .green {
        padding: 1px 17px;
      }
    }
  }
}
.plan-entry-table-container {
  margin-top: 15px;
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }
  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }
  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }
  .el-checkbox__inner:hover {
    border-color: #004ca7;
  }
  .el-checkbox__inner {
    border: 1px solid #004ca7;
    border-radius: 0;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #004ca7;
    border-color: #004ca7;
  }
  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #004ca7;
  }
  .el-checkbox.is-bordered.is-checked {
    border-color: #004ca7;
  }
  .el-checkbox__input.is-focus .el-checkbox__inner {
    border-color: #004ca7;
  }
  .export-button {
    background: #fff6ef;
    border: 1px solid #f3b815;
    width: auto;
    height: 28px;
    line-height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 3px 10px;
    box-sizing: border-box;
    > span {
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }
    > img {
      width: 16px;
      height: 16px;
      margin-right: 5px;
    }
  }

  .lucj-import-button {
    .export-button;
    width: 116px;
    margin: 0 auto 12px;
    background: #f1fff8;
    border: 1px solid #02c86c;
    &:last-child {
      margin-bottom: 0px;
    }
    > span {
      color: #02c86c;
    }
  }
  .lucj-expot-button {
    .export-button;
    background: #fff6ef;
    border: 1px solid #f3b815;
    width: 81px;
    margin: 0 auto 12px;
    &:last-child {
      margin-bottom: 0px;
    }
    > span {
      color: #f3b815;
    }
  }
}
.plsc-button {
  height: 28px;
  background: #ffefef;
  border: 1px solid #fa5339;
  border-radius: 6px;
  color: #ff3819;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  img {
    width: 14px;
    height: 14px;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    margin: 2px 5px 0 0;
  }
}
.button-group {
    cursor: pointer;
    margin-top: 50px;
    text-align: center;

    > div {
      display: inline-block;
      font-size: 18px;
      padding: 6px 22px;
      border-radius: 6px;

      &:nth-child(1) {
        color: #02c86c;
        border: 1px solid #02c86c;
        background: #f1fff8;
      }

      &:nth-child(2) {
        color: #ff3819;
        border: 1px solid #ff3819;
        background: #ffefef;
      }
    }
  }
.el-table {
  ::v-deep td.cell-class {
    line-height: 57px;
    height: 57px;
  }
}
.avue-view {
  // padding: 30px;
}
img {
  width:  80px;
  height: 80px;
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.title1 {
    width: 100%;
    border-radius: 5px 5px 0px 0px;   
    height: 56px;
    line-height: 56px;
    border-radius: 5px 5px 0px 0px;
    background-color: #edf2f9;
    border: 1px solid #004ca7;
    border-bottom: none;
}
.span1 {
    font-size: 18px;
    display: block;
    font-weight: bold;
    padding: 0px 20px;
    color: #004ca7;
    text-align: center;
}
.title2 {
    width: 100%;
    border-radius: 5px 5px 0px 0px;   
    height: 56px;
    line-height: 56px;
    border-radius: 5px 5px 0px 0px;
    background-color: #edf2f9;
    border: 1px solid #004ca7;
    border-bottom: none;
}
.span2 {
    font-size: 18px;
    display: block;
    font-weight: bold;
    padding: 0px 20px;
    color: #004ca7;
    text-align: center;
}
.footer {
  width: 230px;
  margin: 0 auto;
  margin-top: 50px;
  .btn1 {
    width: 87px;
    height: 36px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    opacity: 1;
    border-radius: 6px;
    color: #f3b815;
    margin-right: 40px;
  }
  .btn2 {
    width: 87px;
    height: 36px;
    background: #ffefef;
    border: 1px solid #ff3819;
    opacity: 1;
    border-radius: 6px;
    color: #ff3819;
    margin-left: 100px;
  }
}
@fontFamily:"Microsoft YaHei";
.xpaas-table-class {
    border-top: 1px solid #c7d7eb;
    border-left: 1px solid #004ca7;
    border-right: 1px solid #004ca7;
    border-bottom: 1px solid #004ca7;
    border-radius: 0 0 9px 9px;
    > ::v-deep div.el-table__header-wrapper {
        > table.el-table__header {
        > thead {
            > tr.xpaas-header-row-class {
            padding: 0;
            height: 76px;
            background-color: #edf2f9;
            font-size: 16px;
            font-family: Microsoft YaHei;
            font-weight: bold;
            line-height: 20px;
            color: #004ca7;
            > th.xpaas-header-cell-class {
                font-weight: bold;
                border-right: 1px solid #c7d7eb;
                border-left: 0;
                border-bottom: 1px solid #c7d7eb;
                background-color: #edf2f9;
                > div.cell {
                font-size: 16px;
                font-weight: bold;
                font-family: @fontFamily;
                color: #004ca7;
                }
            }
            }
        }
        }
    }
    > ::v-deep div.el-table__body-wrapper {
        > table.el-table__body {
        > tbody {
            > tr.xpaas-row-class {
            > td.xpaas-header-cell-class {
                border-right: 1px solid #c7d7eb;
                border-left: 0;
                border-bottom: 1px solid #c7d7eb;
                background-color: #edf2f9;
                > div.cell {
                font-size: 16px;
                font-weight: bold;
                font-family: @fontFamily;
                color: #004ca7;
                }
            }
            > td.xpaas-cell-class {
                height: 76px;

                border-right: 1px solid #c7d7eb;
                border-left: 0;
                border-bottom: 1px solid #c7d7eb;
                > div.cell {
                font-weight: normal;
                font-family: @fontFamily;
                color: #004ca7;
                }
            }
            }
        }
        }
    }
}
</style>
